package com.bootcamp.mvc1125.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @program: spring-1125-mvc-java-config
 * @description:
 * @author: Keyu Li
 * @create: 2021-11-25 11:17
 **/


public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    /* Spring容器*/
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfiguration.class};
    }

    /* SpringMVC容器*/
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfiguration.class};
    }

    /* DispatcherServlet 的 url-pattern*/
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    /* 配置 characterEncoding Filter*/
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("utf-8");
        filter.setForceEncoding(true);
        return new Filter[]{filter};
    }
}
